package com.atung.parking.controller;

import com.atung.parking.config.permission.PermissionValid;
import com.atung.parking.config.result.ApiResult;
import com.atung.parking.entity.BusLicensePlate;
import com.atung.parking.enums.AdminType;
import com.atung.parking.request.ByIdRequest;
import com.atung.parking.request.save.SaveOrUpdateLicensePlateRequest;
import com.atung.parking.service.LicensePlateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@Api(tags = "车牌管理")
@RequestMapping("/api/licensePlate")
public class LicensePlateController {

    @Resource
    private LicensePlateService licensePlateService;

    @PostMapping("/app/save")
    @ApiOperation("（小程序）新增车牌")
    @PermissionValid(roleType = {AdminType.USER, AdminType.SUPERADMIN})
    public ApiResult saveLicensePlate(@RequestBody @Valid SaveOrUpdateLicensePlateRequest request) {
        return licensePlateService.saveLicensePlateService(request);
    }

    @PostMapping("/app/set/default")
    @ApiOperation("(小程序)设为默认车牌")
    @PermissionValid(roleType = {AdminType.USER, AdminType.SUPERADMIN})
    public ApiResult setDefaultLicensePlate(@RequestBody @Valid ByIdRequest request) {
        return licensePlateService.setDefaultLicensePlateServcie(request);
    }

    @GetMapping("/app/query")
    @ApiOperation("小程序)获取车牌列表")
    @PermissionValid(roleType = {AdminType.USER})
    public ApiResult queryLicensePlateList() {
        List<BusLicensePlate> busLicensePlates = licensePlateService.queryLicensePlateListService();
        return ApiResult.ok(busLicensePlates);
    }

    @GetMapping("/app/delete")
    @ApiOperation("(小程序)删除车牌列表")
    @PermissionValid(roleType = {AdminType.USER})
    public ApiResult deleteLicensePlate(@RequestBody @Valid ByIdRequest request) {
        return licensePlateService.deleteLicensePlateService(request);

    }
}
